<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=no">
    <title>日新网_我的问答111</title>
    <link rel="stylesheet" href="__TMPL__Public/assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="__TMPL__Public/assets/css/reset.css">
    <link rel="stylesheet" href="__TMPL__Public/assets/css/style.css">
    <script type="text/javascript" src="__TMPL__Public/assets/js/rem.js"></script>
    <style>
        .question_title {
            border: none!important;
            border-bottom: 1px solid #c5c5c5!important;
            border-radius: 0px!important;
            outline: none!important;
            height: .4rem!important;
            line-height: .4rem!important;
        }
    </style>

</head>
<body>
<tc_include file="Public:nav"/>

<div class="comWidth details">
    <form action="" method="post" enctype="multipart/form-data" class="form-horizontal js-ajax-forms">
        <input type="text" name="post[post_title]" class="form-control question_title" placeholder="在这里输入问题">
        <div class="question_write">
            <h3>写问题详情:</h3>
            <div>
                <textarea id="question_show" name="question_show" cols="30" rows="10" placeholder="文本内容"></textarea>
                <textarea id="question_content" name="post[post_content]" style="z-index: -1;position:absolute;top: 2.3rem; width: 0px;height: 0px;"></textarea>
            </div>
            <p class="write_btn ">
                <span class="btn1">提交</span>
                <span class="btn_no">取消</span>
            </p>
        </div>
    </form>
</div>
<!--页脚-->
<tc_include file="Public:footer"/>
<script type="text/javascript" src="__TMPL__Public/assets/js/jquery.1.12.4.js"></script>
<script src="__TMPL__Public/assets/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script src="__PUBLIC__/js/layer/layer_1.js"></script>
<script src="__PUBLIC__/js/validate.js"></script>
<script src="__PUBLIC__/js/ajaxForm.js"></script>
<script>
    var loading = false;

    $(function(){

        $('.btn1').click(function () {
            $('form.js-ajax-forms').submit();
        });

        $('.btn_no').click(function () {
            window.history.go(-1);
        });

        editorcontent = new baidu.editor.ui.Editor({
            initialFrameWidth   : '100%',   //设置编辑器宽度
            initialFrameHeight  : '320',    //设置编辑器高度
            scaleEnabled        : true,     //设置不自动调整高度
        });
        editorcontent.render('question_show');

        // 监听编辑区内容变化
        editorcontent.addListener( 'selectionchange', function() {
            var content = editorcontent.getContent();
            $('#question_content').val(content); // 方便表单提交验证
        });

        var form = $('form.js-ajax-forms');

        //ie处理placeholder提交问题
        if ($.browser && $.browser.msie) {
            form.find('[placeholder]').each(function() {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        }

        //表单验证开始
        form.validate({
            //是否在获取焦点时验证
            onfocusout : false,
            //是否在敲击键盘时验证
            onkeyup : false,
            //当鼠标掉级时验证
            onclick : false,
            // 错误展示
            showErrors : function(errorMap, errorArr) {
                //errorMap {'name':'错误信息'}
                //errorArr [{'message':'错误信息',element:({})}]
                try {
                    $(errorArr[0].element).focus();
                    layer.msg(errorArr[0].message);
                } catch (err) {

                }
                this.defaultShowErrors();
            },
            //指明错误放置的位置
            errorPlacement: function(error, element) {
            },
            //验证规则
            rules : {
                'post[post_title]' : {
                    required : 1
                },
            },
            //验证未通过提示消息
            messages : {
                'post[post_title]' : {
                    required : '请输入问题标题'
                },
            },
            //验证通过，提交表单
            submitHandler : function(forms) {

                if (loading) {
                    layer.load();
                    return;
                }
                loading = true;

                $(forms).ajaxSubmit({
                    url : form.attr('action'),
                    dataType : 'json',
                    success : function(data, statusText, xhr, $form) {
                        layer.msg(data.info, { offset: ['47%', '35%'], time : 3000});
                        if (data.status == 1) {

                            setTimeout(function () {
                                window.location.href = "{:U('Question/Question/center_question')}" + "&list_index=0";
                            }, 3000);
                        }
                        loading = false;
                    }
                });
            }
        });
    });
</script>
</body>
</html>